/
FolderInfo.cs
333 lines (292 loc) · 12.2 KB
/
FolderInfo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
namespace DotNetNuke.Services.FileSystem
{
using System;
using System.Data;
using System.Linq;
using System.Web;
using System.Xml.Serialization;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Security.Permissions;
using Newtonsoft.Json;
[XmlRoot("folder", IsNullable = false)]
[Serializable]
public class FolderInfo : BaseEntityInfo, IHydratable, IFolderInfo
{
// local property declarations
private string displayName;
private string displayPath;
private FolderPermissionCollection folderPermissions;
private int folderMappingId;
/// <summary>Initializes a new instance of the <see cref="FolderInfo"/> class.</summary>
public FolderInfo()
: this(false)
{
}
/// <summary>Initializes a new instance of the <see cref="FolderInfo"/> class.</summary>
/// <param name="portalId"></param>
/// <param name="folderpath"></param>
/// <param name="storageLocation"></param>
/// <param name="isProtected"></param>
/// <param name="isCached"></param>
/// <param name="lastUpdated"></param>
[Obsolete("Deprecated in DotNetNuke 7.1.0. Use the parameterless constructor and object initializers. Scheduled for removal in v10.0.0.")]
public FolderInfo(int portalId, string folderpath, int storageLocation, bool isProtected, bool isCached, DateTime lastUpdated)
: this(Guid.NewGuid(), portalId, folderpath, storageLocation, isProtected, isCached, lastUpdated)
{
}
/// <summary>Initializes a new instance of the <see cref="FolderInfo"/> class.</summary>
/// <param name="uniqueId"></param>
/// <param name="portalId"></param>
/// <param name="folderpath"></param>
/// <param name="storageLocation"></param>
/// <param name="isProtected"></param>
/// <param name="isCached"></param>
/// <param name="lastUpdated"></param>
[Obsolete("Deprecated in DotNetNuke 7.1.0. Use the parameterless constructor and object initializers. Scheduled for removal in v10.0.0.")]
public FolderInfo(Guid uniqueId, int portalId, string folderpath, int storageLocation, bool isProtected, bool isCached, DateTime lastUpdated)
{
this.FolderID = Null.NullInteger;
this.UniqueId = uniqueId;
this.VersionGuid = Guid.NewGuid();
this.WorkflowID = Null.NullInteger;
this.PortalID = portalId;
this.FolderPath = folderpath;
this.StorageLocation = storageLocation;
this.IsProtected = isProtected;
this.IsCached = isCached;
this.LastUpdated = lastUpdated;
}
/// <summary>Initializes a new instance of the <see cref="FolderInfo"/> class.</summary>
/// <param name="initialiseEmptyPermissions"></param>
internal FolderInfo(bool initialiseEmptyPermissions)
{
this.FolderID = Null.NullInteger;
this.UniqueId = Guid.NewGuid();
this.VersionGuid = Guid.NewGuid();
this.WorkflowID = Null.NullInteger;
if (initialiseEmptyPermissions)
{
this.folderPermissions = new FolderPermissionCollection();
}
}
/// <inheritdoc/>
[XmlElement("uniqueid")]
public Guid UniqueId { get; set; }
/// <inheritdoc/>
[XmlElement("versionguid")]
public Guid VersionGuid { get; set; }
/// <inheritdoc/>
[XmlElement("foldername")]
public string FolderName
{
get
{
string folderName = PathUtils.Instance.RemoveTrailingSlash(this.FolderPath);
if (folderName.Length > 0 && folderName.LastIndexOf("/", StringComparison.Ordinal) > -1)
{
folderName = folderName.Substring(folderName.LastIndexOf("/", StringComparison.Ordinal) + 1);
}
return folderName;
}
}
/// <summary>Gets a value indicating whether the folder has any child subfolder.</summary>
[XmlElement("haschildren")]
public bool HasChildren
{
get
{
return FolderManager.Instance.GetFolders(this).Any();
}
}
/// <summary>Gets or sets a reference to the active Workflow for the folder.</summary>
[XmlElement("workflowid")]
public int WorkflowID { get; set; }
/// <summary>Gets or sets a reference to the parent folder.</summary>
[XmlElement("parentid")]
public int ParentID { get; set; }
/// <inheritdoc/>
[XmlElement("physicalpath")]
public string PhysicalPath
{
get
{
string physicalPath;
PortalSettings portalSettings = null;
if (HttpContext.Current != null)
{
portalSettings = PortalController.Instance.GetCurrentPortalSettings();
}
if (this.PortalID == Null.NullInteger)
{
physicalPath = Globals.HostMapPath + this.FolderPath;
}
else
{
if (portalSettings == null || portalSettings.PortalId != this.PortalID)
{
// Get the PortalInfo based on the Portalid
var portal = PortalController.Instance.GetPortal(this.PortalID);
physicalPath = portal.HomeDirectoryMapPath + this.FolderPath;
}
else
{
physicalPath = portalSettings.HomeDirectoryMapPath + this.FolderPath;
}
}
return physicalPath.Replace("/", "\\");
}
}
/// <inheritdoc/>
[XmlElement("portalid")]
public int PortalID { get; set; }
/// <inheritdoc/>
[XmlElement("storagelocation")]
public int StorageLocation { get; set; }
/// <inheritdoc/>
[XmlElement("folderpermissions")]
public FolderPermissionCollection FolderPermissions
{
get
{
return this.folderPermissions ?? (this.folderPermissions = new FolderPermissionCollection(FolderPermissionController.GetFolderPermissionsCollectionByFolder(this.PortalID, this.FolderPath)));
}
}
/// <inheritdoc/>
public bool IsStorageSecure
{
get
{
var folderMapping = FolderMappingController.Instance.GetFolderMapping(this.PortalID, this.FolderMappingID);
return FolderProvider.Instance(folderMapping.FolderProviderType).IsStorageSecure;
}
}
/// <inheritdoc/>
[XmlElement("folderid")]
public int FolderID { get; set; }
/// <inheritdoc/>
[XmlElement("displayname")]
public string DisplayName
{
get
{
if (string.IsNullOrEmpty(this.displayName))
{
this.displayName = this.FolderName;
}
return this.displayName;
}
set
{
this.displayName = value;
}
}
/// <inheritdoc/>
[XmlElement("folderpath")]
public string FolderPath { get; set; }
/// <inheritdoc/>
[XmlElement("displaypath")]
public string DisplayPath
{
get
{
if (string.IsNullOrEmpty(this.displayPath))
{
this.displayPath = this.FolderPath;
}
return this.displayPath;
}
set
{
this.displayPath = value;
}
}
/// <inheritdoc/>
[XmlElement("iscached")]
public bool IsCached { get; set; }
/// <inheritdoc/>
[XmlElement("isprotected")]
public bool IsProtected { get; set; }
/// <summary>Gets or sets a value indicating whether file versions are active for the folder.</summary>
[XmlElement("isversioned")]
public bool IsVersioned { get; set; }
/// <summary>Gets or sets the path this folder is mapped on its provider file system.</summary>
[XmlElement("mappedpath")]
public string MappedPath { get; set; }
/// <inheritdoc/>
[XmlIgnore]
[JsonIgnore]
public DateTime LastUpdated { get; set; }
/// <inheritdoc/>
public int FolderMappingID
{
get
{
if (this.folderMappingId == 0)
{
switch (this.StorageLocation)
{
case (int)FolderController.StorageLocationTypes.InsecureFileSystem:
this.folderMappingId = FolderMappingController.Instance.GetFolderMapping(this.PortalID, "Standard").FolderMappingID;
break;
case (int)FolderController.StorageLocationTypes.SecureFileSystem:
this.folderMappingId = FolderMappingController.Instance.GetFolderMapping(this.PortalID, "Secure").FolderMappingID;
break;
case (int)FolderController.StorageLocationTypes.DatabaseSecure:
this.folderMappingId = FolderMappingController.Instance.GetFolderMapping(this.PortalID, "Database").FolderMappingID;
break;
default:
this.folderMappingId = FolderMappingController.Instance.GetDefaultFolderMapping(this.PortalID).FolderMappingID;
break;
}
}
return this.folderMappingId;
}
set
{
this.folderMappingId = value;
}
}
/// <summary> Gets or sets and sets the Key ID.</summary>
/// <returns>An Integer.</returns>
[XmlIgnore]
[JsonIgnore]
public int KeyID
{
get
{
return this.FolderID;
}
set
{
this.FolderID = value;
}
}
/// <summary> Fills a FolderInfo from a Data Reader.</summary>
/// <param name="dr">The Data Reader to use.</param>
public void Fill(IDataReader dr)
{
this.FolderID = Null.SetNullInteger(dr["FolderID"]);
this.UniqueId = Null.SetNullGuid(dr["UniqueId"]);
this.VersionGuid = Null.SetNullGuid(dr["VersionGuid"]);
this.PortalID = Null.SetNullInteger(dr["PortalID"]);
this.FolderPath = Null.SetNullString(dr["FolderPath"]);
this.MappedPath = Null.SetNullString(dr["MappedPath"]);
this.IsCached = Null.SetNullBoolean(dr["IsCached"]);
this.IsProtected = Null.SetNullBoolean(dr["IsProtected"]);
this.StorageLocation = Null.SetNullInteger(dr["StorageLocation"]);
this.LastUpdated = Null.SetNullDateTime(dr["LastUpdated"]);
this.FolderMappingID = Null.SetNullInteger(dr["FolderMappingID"]);
this.IsVersioned = Null.SetNullBoolean(dr["IsVersioned"]);
this.WorkflowID = Null.SetNullInteger(dr["WorkflowID"]);
this.ParentID = Null.SetNullInteger(dr["ParentID"]);
this.FillBaseProperties(dr);
}
}
}